package nirvana.core.bean.json.str;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

/**
 * 【描 述】：
 * 【环 境】：J2SE 17
 * 【详 细】：
 *
 * @author 李松林
 * @version v1.0 2023/11/20 新建
 * @since 2023/11/20
 */
public class TrimStringDeserializer extends JsonDeserializer<String> {

    /**
     * 处理String字段
     * @param p Parsed used for reading JSON content
     * @param ctxt Context that can be used to access information about
     *   this deserialization activity.
     *
     * @return
     * @throws IOException
     * @throws JacksonException
     */
    @Override
    public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
        return p.getValueAsString().trim();
    }
}
